package com.rede.didiok.admin.restapi.admin;


import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.admin.annotion.AuthorityVerify.AuthorityVerify;
import com.rede.didiok.admin.annotion.OperationLogger.OperationLogger;
import com.rede.didiok.common.annotion.AvoidRepeatableCommit.AvoidRepeatableCommit;
import com.rede.didiok.common.dto.rank.MemberGradeDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.feign.RankFeignClient;
import com.rede.didiok.common.validator.group.Delete;
import com.rede.didiok.common.validator.group.GetList;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.common.validator.group.Update;

/**
 * 榜单成员等级等级表 RestApi
 *
 * @author Rede
 * @since 2023-09-08
 */
@Api(value = "榜单成员等级相关接口", tags = {"榜单成员等级相关接口"})
@RestController
@RequestMapping("/admin/memberGrade")
@Slf4j
public class MemberGradeRestApi {

    @Autowired
    private RankFeignClient rankFeignClient;

    @AuthorityVerify
    @ApiOperation(value = "获取榜单成员等级列表", notes = "获取榜单成员等级列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody MemberGradeDto memberGradeDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("获取榜单成员等级列表");
        return rankFeignClient.getMemberGradePageList(memberGradeDto);
    }

    @AvoidRepeatableCommit
    @AuthorityVerify
    @OperationLogger(value = "增加榜单成员等级")
    @ApiOperation(value = "增加榜单成员等级", notes = "增加榜单成员等级", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody MemberGradeDto memberGradeDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("增加榜单成员等级");
        return rankFeignClient.addMemberGrade(memberGradeDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "编辑榜单成员等级")
    @ApiOperation(value = "编辑榜单成员等级", notes = "编辑榜单成员等级", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody MemberGradeDto memberGradeDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("编辑榜单成员等级");
        return rankFeignClient.editMemberGrade(memberGradeDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "批量删除榜单成员等级")
    @ApiOperation(value = "批量删除榜单成员等级", notes = "批量删除榜单成员等级", response = String.class)
    @PostMapping("/deleteBatch")
    public String delete(@Validated({Delete.class}) @RequestBody List<MemberGradeDto> memberGradeDtoList, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("批量删除榜单成员等级");
        return rankFeignClient.deleteBatchMemberGrade(memberGradeDtoList);
    }

}

